package com.yxj.threadcase1;

import javax.print.attribute.standard.JobKOctets;

public class MyThread9 extends Thread{

    //static表示这个类所有的对象都共享ticket数据
    static int ticket = 0;
    //锁对象，一定是唯一的，static
    //static Object obj = new Object();
    @Override
    public void run() {
        while(true) {
            //同步代码块
            synchronized (MyThread9.class) {
                if(ticket < 100) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    ticket++;
                    System.out.println(getName()+"正在卖第"+ticket+"张票");
                }else {
                    break;
                }
            }
        }
    }
}
